import { useModel } from "umi";

import EditApplication from "../components/tools_application/Edit";
import CreateApplicationType from "../components/tools_application/TypeCreate";
import EditApplicationType from "../components/tools_application/TypeEdit";
import EditApplicationTypeIcon from "../components/tools_application/TypeIcon";
import EditApplicationTypeVersionDescription from "../components/tools_application/VersionDesc";

const useHelperPersonApplication = () => {
    const { setModalVisible, setModalTitle, setModalWidth, setModalComponent } = useModel("global.modal");

    const openEditPersonApplicationModal = (record, reloadData) => {
        setModalTitle("编辑应用信息");
        setModalWidth(600);
        setModalComponent(<EditApplication record={record} reloadData={reloadData} />);
        setModalVisible(true);
    };

    const openCreateApplicationType = (application, applicationTypes, reloadData) => {
        setModalTitle(application.appName);
        setModalVisible(true);
        setModalWidth(600);
        setModalComponent(<CreateApplicationType app={application} types={applicationTypes} reloadData={reloadData} />);
    };

    const openEditApplicationType = (application, item, reloadData) => {
        setModalTitle(application.appName + ` - 编辑【${item.appType}】信息`);
        setModalWidth(600);
        setModalComponent(<EditApplicationType item={item} reloadData={reloadData} />);
        setModalVisible(true);
    };

    const openEditApplicationTypeIcon = (application, item, reloadData) => {
        setModalTitle(application.appName + ` - 【${item.appType}】图标`);
        setModalVisible(true);
        setModalWidth(600);
        setModalComponent(<EditApplicationTypeIcon application={application} type={item} reloadData={reloadData} />);
    };

    const openEditApplicationTypeVerionDesc = (item, reloadData) => {
        setModalTitle("编辑应用版本更新说明");
        setModalWidth(600);
        setModalComponent(<EditApplicationTypeVersionDescription version={item} reloadData={reloadData} />);
        setModalVisible(true);
    };

    return { openEditPersonApplicationModal, openCreateApplicationType, openEditApplicationType, openEditApplicationTypeIcon, openEditApplicationTypeVerionDesc };
};

export default useHelperPersonApplication;
